package com.dong.springaop;

import com.dong.springaop.advice.MyAfterReturningAdvice;
import com.dong.springaop.advice.MyAroundAdvice;
import com.dong.springaop.advice.MyBeforeAdvice;
import com.dong.springaop.advice.MyThrowAdvice;
import com.dong.springaop.pointcut.MyStaticPointcut;
import com.dong.springaop.service.UserService;
import com.dong.springaop.service.impl.UserServiceImpl;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * description
 *
 * @author Administrator 2021/09/13 18:54
 */
public class SpringAopTest {

    public static void main(String[] args) {
        ProxyFactory factory = new ProxyFactory(new UserServiceImpl());
        factory.addAdvice(new MyAroundAdvice());
        factory.addAdvice(new MyThrowAdvice());
        factory.addAdvice(new MyAfterReturningAdvice());
        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
        advisor.setAdvice(new MyBeforeAdvice());
        advisor.setPointcut(new MyStaticPointcut());
        factory.addAdvisor(advisor);

        UserService userService = (UserService) factory.getProxy();
        userService.select();
    }
}
